import { request } from "../../request/index.js"
Page({
  data: {
    goodsObj: {}
  },

  onLoad: function (options) {
    const { goods_id } = options
    this.getGoodsDetail(goods_id)
  },

  // 商品对象
  Goodsinfo:{},

  // 获取商品详情数据
  async getGoodsDetail(goods_id) {
    const res = await request({ url: "/goods/detail", data: { goods_id } })
    const goodsObj = res.data.message
    this.Goodsinfo = goodsObj
    // console.log(res) 
    this.setData({
      // 直接全部赋值
      // goodsObj: res.data.message
      goodsObj:{
        goods_name:goodsObj.goods_name,
        goods_price:goodsObj.goods_price,
        // goods_introduce:goodsObj.goods_introduce,
        goods_introduce:goodsObj.goods_introduce.replace(/\.webp/g,'.jpg'),
        pics:goodsObj.pics
      }
    })
  },

  // 点击轮播图放大预览
  handlePreviewImage(e){
    // console.log("预览")
    // 构造要预览的图片数组
    const urls = this.Goodsinfo.pics.map(v=>v.pics_mid)
    // 接受传递过来的图片url
    const current = e.currentTarget.dataset.url
    console.log(e)
    // console.log(current)
    wx.previewImage({
      current,
      urls
    });
  }

})